﻿@{
    ViewBag.Title = "Form";
    Layout = "~/Views/Shared/_ManufactureList.cshtml";
}
<script type="text/javascript">
    var currRowId = 0;
    var status = '@ViewBag.status';
    var number = '@ViewBag.number';
    $(function () {
        initControl();
        partsList();
    });
    function initControl() {
        var myLayout = $('#layout').layout({ resizable: false });
        myLayout.sizePane("west", 300);
        if (status == 'I') {
            
        } else if (status == 'U') {
            var data = eval(@Html.Raw(ViewBag.oldEntity));
            for (var p in data) {
                $("#"+p).val(data[p]);
            }
            $("#FProductionNO").prop("disabled", true);
            $("#FProductionName").prop("disabled", true);
            $("#FProductionTypeNO").prop("disabled", true);
            $("#FContainerNO").prop("disabled", true);
        }
        $('select').bindSelect();
    }
    function partsList() {
        var $partsList = $("#partsList");
        $partsList.dataGrid({
            url: "/BOM/Product/GetPartsJson2",
            height: $(window).height() - 120,
            colModel: [
                { label: '零件编号', name: 'FProductionNO', width: 115, align: 'left', sortable: false },
                { label: '零件名称', name: 'FProductionName', width: 166, align: 'left', sortable: false }
            ],
            pager: "#partsPager",
            sortname: 'FProductionNO asc',
            rownumbers: false,
            viewrecords: true,
            loadComplete: function () {
                var ids = $partsList.jqGrid('getDataIDs');
                var length = ids.length;
                if (length > 0) {
                    if (currRowId == 0) {
                        currRowId = 1;
                    } else if (currRowId > length) {
                        currRowId = length;
                    }
                }
                if (currRowId > 0) {
                    if (status == 'I') {
                        $partsList.jqGrid('setSelection', currRowId);
                    }
                }
            },
            onSelectRow: function (rowId) {
                var rowData = $partsList.jqGrid('getRowData', rowId);
                $("#FProductionNO").val(rowData.FProductionNO);
                $("#FProductionName").val(rowData.FProductionName);
            },
            beforeSelectRow: function (rowid, e) {
                if (status != 'I') {
                    return false;
                }
            }
        });
        $("#btn_search").click(function () {
            $partsList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_company() {
        var title = '选择发交单位：';
        var url = '/BOM/Manufacture/ChooseSupplier?numbers=' + $("#FHappComNOList").val() + '&names=' + encodeURI($("#FDesc").val());
        $.detailOpenTop({
            id: "Detail",
            title: title,
            url: url,
            width: 840,
            height: 500
        });
    }
    function btn_ok() {
        submitForm();
    }
    function submitForm() {
        if (!$('#form1').formValid()) {
            return false;
        }
        $.submitForm({
            url: "/BOM/Manufacture/SubmitPackingListForm?status=" + status + "&keyValue=" + number,
            param: $("#form1").formSerialize(),
            success: function (result) {
                if (status == 'I') {
                    parent.reloadGrid(result.data);
                } else {
                    parent.reloadGrid();
                }
                parent.$.detailClose();
            }
        })
    }
    function btn_cancel() {
        parent.$.detailClose();
    }
    function SetCompany(list) {
        var numbers = [];
        var names = [];
        for (var i = 0; i < list.length; i++) {
            numbers.push(list[i].UnitNO);
            names.push(list[i].UnitShortName);
        }
        $("#FHappComNOList").val(numbers.join(','));
        $("#FDesc").val(names.join(','));
    }
</script>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        @RenderPage("~/Views/Shared/_CommonStampingList.cshtml")
    </div>
    <div class="ui-layout-center">
        <form id="form1">
            <div style="padding-left:20px;">
                <table class="form" style="width:900px;text-align:right;margin:15px;border-bottom:2px solid #ccc;">
                    <tr>
                        <td class="formValue" width="160px;">
                            <div class="btn-group dialog-title">
                                @(ViewBag.status == "U" ? "修改" : "新增")包装工艺清单信息
                            </div>
                        </td>
                        <td class="formValue input-width-185" style="width:420px;">
                            &nbsp;
                        </td>
                        <td style="width: 300px; padding: 5px 10px;">
                            <div class="btn-group" style="margin-right:20px;">
                                <a id="" class="btn btn-primary center-block" onclick="btn_ok()"><span class="glyphicon glyphicon-ok"></span> 确认</a>
                            </div>
                            <div class="btn-group">
                                <a id="" class="btn btn-primary center-block" onclick="btn_cancel()"><span class="glyphicon glyphicon-remove"></span> 取消</a>
                            </div>
                        </td>
                    </tr>
                </table>
                <table class="form" style="width: 900px;margin-left:15px;">
                    <tr>
                        <th class="formTitle" style="width:100px;">零件编号</th>
                        <td class="formValue input-width-185" style="width:280px;">
                            <input id="FProductionNO" name="FProductionNO" type="text" class="form-control required" readonly="readonly" value="" />
                            <input id="FStorTransID" name="FStorTransID" type="hidden" value="" />                        
                        </td>
                        <th class="formTitle" style="width:100px">&nbsp;</th>
                        <td class="formValue">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">零件名称</th>
                        <td class="formValue input-width-320" colspan="3">
                            <input id="FProductionName" name="FProductionName" type="text" class="form-control" readonly="readonly" value="" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">零件分类</th>
                        <td class="formValue input-width-185">
                            <select id="FProductionTypeNO" name="FProductionTypeNO" class="form-control">
                                @foreach (var item in ViewBag.fproductionType)
                                {
                                    <option value="@item.FTypeNO">@item.FTypeNO @item.FTypeName</option>
                                }
                            </select>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">工位器具</th>
                        <td class="formValue input-width-185">
                            <select id="FContainerNO" name="FContainerNO" class="form-control">
                                @foreach (var item in ViewBag.fcontainer)
                                {
                                    <option value="@item.FContainerNO">@item.FContainerNO @item.FContainerName</option>
                                }
                            </select>
                        </td>
                        <th class="formTitle">标准装箱</th>
                        <td class="formValue input-width-40">
                            <input id="Fcontent" name="Fcontent" type="text" class="form-control text-right required digits" />&nbsp;<label>件/箱</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">托盘编号</th>
                        <td class="formValue input-width-185">
                            <select id="PalletNO" name="PalletNO" class="form-control">
                                @foreach (var item in ViewBag.pallet)
                                {
                                    <option value="@item.PalletNO">@item.PalletNO</option>
                                }
                            </select>
                        </td>
                        <th class="formTitle">托盘容量</th>
                        <td class="formValue input-width-40">
                            <input id="FPalletContent" name="FPalletContent" type="text" class="form-control text-right required digits" />&nbsp;<label>箱/托</label>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">发交单位</th>
                        <td class="formValue input-width-740" colspan="3">
                            <div class="btn-group">
                                <input id="FHappComNOList" name="FHappComNOList" type="text" class="form-control" readonly="readonly" />
                            </div>
                            <div class="btn-group">
                                <a id="btn_company" class="btn btn-primary center-block btn-1" onclick="btn_company()"><span class="glyphicon glyphicon-search"></span></a>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">单位名称</th>
                        <td class="formValue input-width-740" colspan="3">
                            <input id="FDesc" name="FDesc" type="text" class="form-control" readonly="readonly" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">收发方式</th>
                        <td class="formValue input-width-105">
                            <select id="FBZ" name="FBZ" class="form-control">
                                <option value="A">A 总</option>
                                <option value="B">B 入</option>
                                <option value="Y">Y 出</option>
                            </select>
                        </td>
                        <th class="formTitle">&nbsp;</th>
                        <td class="formValue input-width-320">
                            &nbsp;
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </div>
</div>

